package org.dgm.crmdbtest.comm;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.dgm.dgmJar.propertyUtil.DCommProperty;
import org.junit.Test;
import org.test.connectDB.comm.IDBOper;
import org.test.connectDB.comm.OracleDataBaseComm;

import com.asiainfo.crm.common.util.PwdUtil;

public class DataComm {

	Logger log = Logger.getLogger(this.getClass());

	IDBOper jycrmoper;
	IDBOper jyggdboper;

	public DataComm() throws Exception {
		super();
		jycrmoper = new OracleDataBaseComm("/jycrm.properties");
		jyggdboper = new OracleDataBaseComm("/jyggdb.properties");
	}

	public void testMain_Link_851() throws Exception {

		// 查出主要联系人
		String main_link_851 = DCommProperty.getPropertyInstance(
				"/sql.properties").getProperty("main_link_851");
		List<Map> resultList = jyggdboper.queryByPage(main_link_851, 1, 10); // 查出主要联系人
		String serviceNums = "";
		String group_cust_id = "";
		for (Map map : resultList) {
			serviceNums += "'" + map.get("BILL_ID") + "',";
			group_cust_id += "'" + map.get("GROUP_CUST_ID") + "',";
		}
		serviceNums = serviceNums.substring(0, serviceNums.length() - 1);
		group_cust_id = group_cust_id.substring(0, group_cust_id.length() - 1);

		// 主要联系人号码和密码
//		String bill_id_passwordsql = DCommProperty.getPropertyInstance(
//				"/sql.properties").getProperty("bill_id_password");
//		bill_id_passwordsql = bill_id_passwordsql.replace("$serviceNums",
//				serviceNums);
//		List<Map> serviceNumList = jycrmoper.queryByPage(bill_id_passwordsql,
//				1, 10);
//		for (Map map2 : serviceNumList) {
//			log.info(map2.get("BILL_ID") + ":"
//					+ PwdUtil.decipher((String) map2.get("PASSWORD")) + ":"
//					+ map2.get("CUST_ID"));
//		}
		so1_ins_user_851(serviceNums);
		

		// 集团号码和密码
		String group_pwd = DCommProperty.getPropertyInstance("/sql.properties")
				.getProperty("group_pwd");
		group_pwd = group_pwd.replace("$group_cust_id", group_cust_id);
		List<Map> grouplist = jyggdboper.queryByPage(group_pwd, 1, 10);
		for (Map map2 : grouplist) {
			log.info(map2.get("GROUP_ID") + ":"
					+ PwdUtil.decipher((String) map2.get("CUST_PASSWORD"))
					+ ":" + map2.get("GROUP_CUST_ID"));
		}

		jycrmoper.close();
		jyggdboper.close();
	}
	
	
	/**
	 * 普通用户的号码和密码
	 * @param serviceNums 形如 15000000000,12300000000
	 * @author：denggm@asiainfo-linkage.com
	 * @Jan 15, 2013 2:10:00 PM
	 */
	public void  so1_ins_user_851(String serviceNums) {
		//号码和密码
		String bill_id_passwordsql = DCommProperty.getPropertyInstance(
				"/sql.properties").getProperty("bill_id_password");
		bill_id_passwordsql = bill_id_passwordsql.replace("$serviceNums",serviceNums);
		List<Map> serviceNumList = jycrmoper.queryByPage(bill_id_passwordsql,
				1, 10);
		for (Map map2 : serviceNumList) {
			log.info(map2.get("BILL_ID") + ":"
					+ PwdUtil.decipher((String) map2.get("PASSWORD")) + ":"
					+ map2.get("CUST_ID"));
		}
	}

}
